package com.zys.el.time.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zys.el.time.common.exception.sql.SqlException;
import com.zys.el.time.entity.ChannelSubscribe;
import com.zys.el.time.service.ChannelSubscribeService;
import com.zys.el.time.mapper.ChannelSubscribeMapper;
import org.springframework.stereotype.Service;


@Service
public class ChannelSubscribeServiceImpl extends ServiceImpl<ChannelSubscribeMapper, ChannelSubscribe>
        implements ChannelSubscribeService {

    @Override
    public void changeSubStatus(ChannelSubscribe channelSubscribe) {
        if (channelSubscribe.getStatus()) { // 新增记录
            boolean b = this.save(channelSubscribe);
            if (!b) {
                throw new SqlException("订阅频道异常");
            }
        } else { // 删除记录
            QueryWrapper<ChannelSubscribe> qw = new QueryWrapper<>();
            qw.lambda().eq(ChannelSubscribe::getChannelId, channelSubscribe.getChannelId())
                    .eq(ChannelSubscribe::getUserId, channelSubscribe.getUserId());
            this.remove(qw);
        }
    }
}




